﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace AgvSystem.Web.Agv_Info
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int Agv_Num=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(Agv_Num);
				}
			}
		}
			
	private void ShowInfo(int Agv_Num)
	{
		AgvSystem.BLL.Agv_Info bll=new AgvSystem.BLL.Agv_Info();
		AgvSystem.Model.Agv_Info model=bll.GetModel(Agv_Num);
		this.lblAgv_Num.Text=model.Agv_Num.ToString();
		this.txtAgv_Speed.Text=model.Agv_Speed.ToString();
		this.txtAgv_Voltage.Text=model.Agv_Voltage.ToString();
		this.txtAgv_Distance.Text=model.Agv_Distance.ToString();
		this.txtAgv_Direction.Text=model.Agv_Direction.ToString();
		this.txtAgv_State.Text=model.Agv_State.ToString();
		this.txtAgv_Error_Message.Text=model.Agv_Error_Message.ToString();
		this.txtAgv_Target_Station_Num.Text=model.Agv_Target_Station_Num.ToString();
		this.txtAgv_Current_Station_Num.Text=model.Agv_Current_Station_Num.ToString();
		this.txtAgv_Ip_Address.Text=model.Agv_Ip_Address;
		this.txtAgv_Receive_Time.Text=model.Agv_Receive_Time.ToString();

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(!PageValidate.IsNumber(txtAgv_Speed.Text))
			{
				strErr+="Agv_Speed格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtAgv_Voltage.Text))
			{
				strErr+="Agv_Voltage格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtAgv_Distance.Text))
			{
				strErr+="Agv_Distance格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtAgv_Direction.Text))
			{
				strErr+="Agv_Direction格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtAgv_State.Text))
			{
				strErr+="Agv_State格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtAgv_Error_Message.Text))
			{
				strErr+="Agv_Error_Message格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtAgv_Target_Station_Num.Text))
			{
				strErr+="Agv_Target_Station_Num格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtAgv_Current_Station_Num.Text))
			{
				strErr+="Agv_Current_Station_Num格式错误！\\n";	
			}
			if(this.txtAgv_Ip_Address.Text.Trim().Length==0)
			{
				strErr+="Agv_Ip_Address不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtAgv_Receive_Time.Text))
			{
				strErr+="Agv_Receive_Time格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int Agv_Num=int.Parse(this.lblAgv_Num.Text);
			int Agv_Speed=int.Parse(this.txtAgv_Speed.Text);
			int Agv_Voltage=int.Parse(this.txtAgv_Voltage.Text);
			int Agv_Distance=int.Parse(this.txtAgv_Distance.Text);
			int Agv_Direction=int.Parse(this.txtAgv_Direction.Text);
			int Agv_State=int.Parse(this.txtAgv_State.Text);
			int Agv_Error_Message=int.Parse(this.txtAgv_Error_Message.Text);
			int Agv_Target_Station_Num=int.Parse(this.txtAgv_Target_Station_Num.Text);
			int Agv_Current_Station_Num=int.Parse(this.txtAgv_Current_Station_Num.Text);
			string Agv_Ip_Address=this.txtAgv_Ip_Address.Text;
			DateTime Agv_Receive_Time=DateTime.Parse(this.txtAgv_Receive_Time.Text);


			AgvSystem.Model.Agv_Info model=new AgvSystem.Model.Agv_Info();
			model.Agv_Num=Agv_Num;
			model.Agv_Speed=Agv_Speed;
			model.Agv_Voltage=Agv_Voltage;
			model.Agv_Distance=Agv_Distance;
			model.Agv_Direction=Agv_Direction;
			model.Agv_State=Agv_State;
			model.Agv_Error_Message=Agv_Error_Message;
			model.Agv_Target_Station_Num=Agv_Target_Station_Num;
			model.Agv_Current_Station_Num=Agv_Current_Station_Num;
			model.Agv_Ip_Address=Agv_Ip_Address;
			model.Agv_Receive_Time=Agv_Receive_Time;

			AgvSystem.BLL.Agv_Info bll=new AgvSystem.BLL.Agv_Info();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
